﻿using vroom.wcf.protobuf.service.common;
using vroom.wcf.service.protobuf.pocos;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace vroom.wcf.tcponly.client
{
	class TestClient
	{
		static void Main(string[] args)
		{
			/*
			ServiceReference.PosServiceClient client = new ServiceReference.PosServiceClient();

			Stopwatch sw = new Stopwatch();
			sw.Reset();
			sw.Start();
			Bucket[] res = client.GetBucketedPositions(new DateTime(2015, 2, 3));
			sw.Stop();

			Console.WriteLine("Elapsed: " + sw.ElapsedMilliseconds / 1000 + " seconds");	
			*/

			NetTcpBinding binding = new NetTcpBinding() { MaxReceivedMessageSize = 2000000000, MaxBufferSize = 2000000000, MaxBufferPoolSize = 2000000000 };
			binding.ReaderQuotas.MaxDepth = 32;
			EndpointAddress endPoint = new EndpointAddress("net.tcp://<HOSTNAME>:9898/PosService");
			ChannelFactory<IPosService> channelFactory = new ChannelFactory<IPosService>(binding, endPoint);
			//channelFactory.Endpoint.Behaviors.Add(new ProtoEndpointBehavior());


			IPosService _client = null;

			try
			{
				_client = channelFactory.CreateChannel();

				Stopwatch sw = new Stopwatch();
				sw.Reset();
				sw.Start();
				Bucket[] results = _client.GetBucketedPositions(new DateTime(2015, 2, 3));
				sw.Stop();
				Console.WriteLine("Elapsed: " + sw.ElapsedMilliseconds / 1000 + " seconds");

				((ICommunicationObject)_client).Close();
			}
			catch
			{
				if (_client != null)
				{
					((ICommunicationObject)_client).Abort();
				}
			}

		}
	}
}
